package com.greenline.search.test.test.queryanalysis;

import com.greenline.search.test.utils.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: liulei
 * Date: 13-12-23
 * Time: 下午3:49
 * To change this template use File | Settings | File Templates.
 */
public class AnalsisQueryAnalysisResult {
    private static Logger logger = LoggerFactory.getLogger(AnalsisQueryAnalysisResult.class);
    public static void main(String[] args) {
        String classPath = FileUtils.class.getResource("/").getPath();
        String filePath = classPath+"dic/hospital_search_analysis2.log";
        List<String> keywordList = FileUtils.readFileAsString(filePath,"UTF-8");
        long startTime = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer();
        for(String keyword : keywordList){
            String[] splitByTab = keyword.split("\t");
            System.out.println("the length of split by tab is "+splitByTab.length);
            System.out.println("the keyword is " + keyword);
            String[] splitByBlank = splitByTab[1].split(" ");
            String returnCount = splitByBlank[splitByBlank.length-1];
            int wordLength = splitByBlank.length / 2;
            String tokenWord = "";
            for(int i = 0; i < wordLength; i++){
                tokenWord += splitByBlank[i];
                if(i != wordLength - 1){
                    tokenWord += " ";
                }
            }
            String tokenType = "";
            for(int j = wordLength; j < splitByBlank.length-1; j++){
                tokenType += splitByBlank[j];
                if(j != splitByBlank.length - 2){
                    tokenType += " ";
                }
            }
            sb.append(splitByTab[0] + "\t" + tokenWord + "\t" + tokenType + "\t" + returnCount);
            sb.append("\n");
        }
        logger.info(sb.toString());
        System.out.println("test end...");
        long costTime = System.currentTimeMillis() - startTime;
        System.out.println("The totalTime is " + (costTime/1000) + " seconds.");
    }
}
